﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Asp_UserControls_CreateCredentials : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {        
    }

    protected void CreateCredentials_Click(object sender, EventArgs e)
    {     
        if (x_usernameValidator.IsValid && x_passwordValidator.IsValid && x_passwordEmptyValidator.IsValid && x_password_repeatValidator.IsValid && x_password_repeatEmptyValidator.IsValid)
        {
            string f_password = Hasher.SHA256(System.Text.Encoding.UTF8.GetBytes(x_password.Text));

            if (LoginHandler.CreateLoginCredentials(x_username.Text, f_password))
            {
                Server.Transfer(Paths.admin_index);
            }
            else
            {
                x_errorPanel.Visible = true;
                x_errorLabel.Text = "Failed to create login credentials";
            }
        }           
    }
}